class Solution {
    public int numRookCaptures(char[][] board) {
        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 8; j++) {
                if(board[i][j]=='R'){
                    return fun(i,j,board);
                }
            }
        }
        return 0;
    }
    public int fun(int x,int y,char[][] board){
        int ans=0;
        for (int i = x+1; i < 8; i++) {
            if(board[i][y]=='P'){
                ans++;
                break;
            }
            if(board[i][y]=='B'){
                break;
            }
        }
        for (int i = x-1; i >= 0; i--) {
            if(board[i][y]=='P'){
                ans++;
                break;
            }
            if(board[i][y]=='B'){
                break;
            }
        }
        for (int i = y+1; i < 9; i++) {
            if(board[x][i]=='P'){
                ans++;
                break;
            }
            if(board[x][i]=='B'){
                break;
            }
        }
        for (int i = y-1; i >= 0; i--) {
            if(board[x][i]=='P'){
                ans++;
                break;
            }
            if(board[x][i]=='B'){
                break;
            }
        }
        return ans;
    }
}